package com.xm.service.service.impl;

import com.alibaba.excel.EasyExcel;
import com.xm.listener.GoodsListener;

import com.xm.mapper.GoodsMapper;
import com.xm.pojo.Goods;
import com.xm.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * 业务逻辑层（service）：处理业务，做一些判断等等...
 */
@Service//PatientService ps = new PatientServiceImpl(); -> ps对象已经放到spring容器中
public class  GoodsServiceImpl implements GoodsService{

    @Autowired
    private GoodsMapper goodsMapper;

    @Override
    public List<Goods> findAll() {
        return goodsMapper.findAll();
    }

    @Override
    public void add(Goods goods) {
goodsMapper.add(goods);
    }

    @Override
    public void logicDelete(Goods goods) {
goodsMapper.logicDelete(goods);
    }

    @Override
    public void updateGoods(Goods goods) {
goodsMapper.updateGoods(goods);
    }

    @Override
    public void batchDel(Integer[] ids) {
goodsMapper.batchDel(ids);
    }

    @Override
    public List<Goods> findByIds(Integer[] ids) {
        return goodsMapper.findByIds(ids);
    }

    @Override
    public void upload(MultipartFile file) {
        InputStream inputStream = null;

        //获取输入流
        try {
            inputStream = file.getInputStream();
        } catch (IOException e) {
            e.printStackTrace();
        }

        // 这里 需要指定读用哪个class去读，然后读取第一个sheet 文件流会自动关闭
        EasyExcel.read(inputStream,Goods.class, new GoodsListener(goodsMapper)).sheet().doRead();
    }

    @Override
    public List<Goods> findDeleted() {
        return goodsMapper.findDeleted();
    }

    @Override
    public void restoreById(Goods goods) {
goodsMapper.restoreById(goods);
    }

    @Override
    public void batchRes(Integer[] ids) {
goodsMapper.batchRes(ids);
    }

    @Override
    public void deleteById(String id) {
goodsMapper.deleteById(id);
    }

    @Override
    public List<Goods> findById(String v) {
        return goodsMapper.findById(v);
    }

    @Override
    public List<Goods> findByGoodsName(String v) {
        return goodsMapper.findByGoodsName(v);
    }

    @Override
    public List<Goods> findByGoodsMoney(String v) {
        return goodsMapper.findByGoodsMoney(v);
    }

    @Override
    public List<Goods> findByGoodsIll(String v) {
        return goodsMapper.findByGoodsIll(v);
    }

    @Override
    public Integer getgoodsNum() {
        return goodsMapper.getgoodsNum();
    }

}
